package database

import (
	"xadmin/backend/internal/model"

	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

func InitSQLite(dbPath string) (*gorm.DB, error) {
	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
	if err != nil {
		return nil, err
	}

	// 自动迁移
	err = db.AutoMigrate(&model.User{}, &model.Role{}, &model.Permission{})
	if err != nil {
		return nil, err
	}

	return db, nil
}
